package com.huifer.wgx.controller;

import com.huifer.wgx.model.ResultLineAttrEntity;
import com.huifer.wgx.model.ResultPointAttrEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.repository.ResultLineAttrRepository;
import com.huifer.wgx.service.ResultLineAttrService;
import com.huifer.wgx.service.ResultPointAttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : ResultLineAttrController </p>
 * <p>Description : 成果线额外属性</p>
 *
 * @author huifer
 * @date 2019-03-15
 */
@RestController
@RequestMapping("result_line_attr")
@Api(tags = "ResultLineAttrController", description = "成果线额外属性管理")
public class ResultLineAttrController {


    @Autowired
    private ResultLineAttrService lineAttrService;
    private CommonResult commonResult = new CommonResult();


    @ApiOperation("创建额外相等属性")
    @PostMapping("/save")
    public ResponseEntity saveResultPointAttrEntity(
            ResultLineAttrEntity resultLineAttrEntity) {
        try {
            ResultLineAttrEntity save = lineAttrService.save(resultLineAttrEntity);
            return ResponseEntity.ok(commonResult.success(save));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有成果线段额外属性")
    @GetMapping("/find_all")
    public ResponseEntity findAll(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(lineAttrService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }
}
